<!DOCTYPE html>












  


<html class="theme-next muse use-motion" lang="cn">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">






  
  
    
      
    
    
      
    
  <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
  <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-flash.min.css" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



















  
  
  
  

  
    
    
  

  
    
      
    

    
  

  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic|Monda:300,300italic,400,400italic,700,700italic|Lobster Two:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.4.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.4.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.4.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '6.4.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="你不想为你的信仰冒一下险吗？难道想等你老了，再后悔莫及吗？  0x01 nmap简介Nmap（网络映射器）是一款用于网络发现和安全审计的网络安全工具，它是自由软件。                                                        －－维基百科">
<meta name="keywords" content="nmap">
<meta property="og:type" content="article">
<meta property="og:title" content="nmap插件编写">
<meta property="og:url" content="https://lengjibo.github.io/nmapnse/index.html">
<meta property="og:site_name" content="冷逸的个人博客|开往安河桥北~">
<meta property="og:description" content="你不想为你的信仰冒一下险吗？难道想等你老了，再后悔莫及吗？  0x01 nmap简介Nmap（网络映射器）是一款用于网络发现和安全审计的网络安全工具，它是自由软件。                                                        －－维基百科">
<meta property="og:locale" content="cn">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/0.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/1.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/2.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/3.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/4.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/5.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/6.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/7.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/8.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/9.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/10.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/11.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/12.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/13.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/14.png">
<meta property="og:image" content="https://lengjibo.github.io/images/nmapnse/15.png">
<meta property="og:updated_time" content="2020-02-27T07:07:28.271Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="nmap插件编写">
<meta name="twitter:description" content="你不想为你的信仰冒一下险吗？难道想等你老了，再后悔莫及吗？  0x01 nmap简介Nmap（网络映射器）是一款用于网络发现和安全审计的网络安全工具，它是自由软件。                                                        －－维基百科">
<meta name="twitter:image" content="https://lengjibo.github.io/images/nmapnse/0.png">



  <link rel="alternate" href="/../../.deploy_git/atom.xml" title="冷逸的个人博客|开往安河桥北~" type="application/atom+xml" />




  <link rel="canonical" href="https://lengjibo.github.io/nmapnse/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>nmap插件编写 | 冷逸的个人博客|开往安河桥北~</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="cn">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">冷逸的个人博客|开往安河桥北~</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="Toggle navigation bar">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />Startseite</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-about">
    <a href="/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />Über</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />Tags</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />Kategorien</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />Archiv</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-book">
    <a href="/book/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-book"></i> <br />book</a>
  </li>

      
      
    </ul>
  

  
    

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://lengjibo.github.io/nmapnse/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="冷逸">
      <meta itemprop="description" content="做一个温柔的人...">
      <meta itemprop="image" content="http://ww1.sinaimg.cn/large/007F8GgBly1g7vony4ltaj308w08wq30.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="冷逸的个人博客|开往安河桥北~">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">nmap插件编写
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Veröffentlicht am</span>
              

              
                
              

              <time title="Post created: 2020-02-09 09:56:56" itemprop="dateCreated datePublished" datetime="2020-02-09T09:56:56+08:00">2020-02-09</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Edited on</span>
                
                <time title="Updated at: 2020-02-27 15:07:28" itemprop="dateModified" datetime="2020-02-27T15:07:28+08:00">2020-02-27</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">in</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/web安全/" itemprop="url" rel="index"><span itemprop="name">web安全</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="post-meta-item-icon"
            >
            <i class="fa fa-eye"></i>
             Views:  
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>你不想为你的信仰冒一下险吗？难道想等你老了，再后悔莫及吗？</p>
<hr>
<h2 id="0x01-nmap简介"><a href="#0x01-nmap简介" class="headerlink" title="0x01 nmap简介"></a>0x01 nmap简介</h2><p>Nmap（网络映射器）是一款用于网络发现和安全审计的网络安全工具，它是自由软件。<br>                                                        －－维基百科</p>
<a id="more"></a>
<p><strong>nmap的执行原理如下：</strong></p>
<p><img src="../images/nmapnse/0.png" alt="image"></p>
<p><strong>nmap的目录结构如下：</strong></p>
<p><img src="../images/nmapnse/1.png" alt="image"></p>
<p>扫描的端口状态如下：</p>
<ul>
<li>Open(开放的): 应用程序正在这个端口上监听连接。</li>
<li>losed(关闭的): 端口对探测做出了响应，但是现在没有应用程序在监听这个端口。</li>
<li>Filtered(过滤的): 端口没有对探测做出响应。同时告诉我们探针可能被一些过滤器（防火墙）终止了。</li>
<li>Unfiltered(未被过滤的):端口对探测做出了响应，但是Nmap无法确定它们是关闭还是开放。</li>
<li>Open/Filtered: 端口被过滤或者是开放的，Nmap无法做出判断。</li>
<li>Closed/Filtered: 端口被过滤或者是关闭的，Nmap无法做出判断。</li>
</ul>
<p>TCP标志位：</p>
<ul>
<li>SYN(synchronous建立联机)</li>
<li>ACK(acknowledgement 确认)</li>
<li>PSH(push传送)</li>
<li>FIN(finish结束)</li>
<li>RST(reset重置)</li>
<li>URG(urgent紧急)</li>
</ul>
<p>在nmap中提供了大量的脚本文件供我们使用，脚本为lua编写的nse文件，常见的脚本用法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">-sC: 使通用scripts生效</span><br><span class="line">--script: 指定自己的脚本文件</span><br><span class="line">--script-trace: 查看脚本执行过程</span><br><span class="line">-A: 同时进行版本探测和脚本扫描</span><br><span class="line"></span><br><span class="line">为了不进行主机发现也不进行端口扫描，直接使用自定义的脚本探测。可以使用下面的选项：</span><br><span class="line">-Pn -sn --script</span><br><span class="line"></span><br><span class="line">--script-args和--script-args-file，指定脚本要读入的参数</span><br><span class="line">nmap --script snmp-sysdescr --script-args snmpcommunity=admin example.com</span><br><span class="line"></span><br><span class="line">nmap --script default,safe 加载default和safe类脚本。</span><br></pre></td></tr></table></figure>
<p>关于nmap脚本的分类可以查看官方文档：<a href="https://nmap.org/book/nse-usage.html#nse-categories" target="_blank" rel="noopener">https://nmap.org/book/nse-usage.html#nse-categories</a></p>
<p>根据脚本的运行阶段不同分为四类：Prerule scripts、Host scripts、Service scripts、Postrule scripts。</p>
<h2 id="0x02-lua语言"><a href="#0x02-lua语言" class="headerlink" title="0x02 lua语言"></a>0x02 lua语言</h2><p><a href="https://www.runoob.com/lua/lua-tutorial.html" target="_blank" rel="noopener">Lua 教程 | 菜鸟教程</a></p>
<h2 id="0x03-nse脚本编写"><a href="#0x03-nse脚本编写" class="headerlink" title="0x03 nse脚本编写"></a>0x03 nse脚本编写</h2><h3 id="nse基本格式"><a href="#nse基本格式" class="headerlink" title="nse基本格式"></a>nse基本格式</h3><p>我们这里使用Halcyon这个IDE先来随便打开一个nse看一下：</p>
<p><img src="../images/nmapnse/2.png" alt="image"></p>
<p>一个完整的NSE脚本通常都有这么几个部分的代码字段：</p>
<p><strong>1、description：</strong></p>
<p>脚本的描述。</p>
<p><strong>2、catagories：</strong></p>
<p>脚本的分类。nmap除了可以指定单个脚本，还能够指定一类脚本，比如default，如果没有使用–script时，默认会加载这类脚本。</p>
<p><strong>3、rule：</strong></p>
<p>脚本的触发规则（一般是一个lua函数，返回值只有true和false），触发脚本执行的条件会在rule字段中定义。</p>
<p>Nmap使用的规则是一个lua函数，用来决定是否执行脚本的action，会返回true或者false。如果返回值为true的话会执行脚本的action函数。</p>
<p>用来决定规则真假的通常是基于规则的类型以及传递给它的主机和端口的信息。</p>
<p><strong>4、action：</strong></p>
<p>脚本具体执行内容。rule触发规则为真时执行action定义的函数。</p>
<h3 id="调用规则"><a href="#调用规则" class="headerlink" title="调用规则"></a>调用规则</h3><ul>
<li>prerule()：<br>不接收参数，脚本只运行一次，在主机发现之前，发生在预扫描阶段。返回的值永远为真。</li>
<li>hostrule(host)：<br>设定参数为目标的ip地址或主机名，nmap完成了主机发现之后再运行脚本。</li>
<li>portrule(host,port)：<br>设定参数需要主机以及端口。在所有主机被扫描完成之后运行，每个端口运行一次，处于open，open|filtered，或者unfiltered状态的所有端口。</li>
<li>postrule()：<br>不接收参数，nmap完成所有主机已经被扫描后，在脚本的后扫描阶段。返回的值永远为真。</li>
</ul>
<p>官方介绍如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hostrule和portrule运行在被主机被扫描完成之后。hostrule和portrule对应函数返回true时，都会执行一次action函数。</span><br><span class="line">当前对于prerule和postrule之间选择的标准是这样：如果脚本在做主机发现或者其他的网络操作那就应该使用prerule。</span><br><span class="line">postrule是为了保存在扫描期间的数据报告和统计。</span><br></pre></td></tr></table></figure>
<p>我们可以编写一个简单的脚本来进行测试：</p>
<p><img src="../images/nmapnse/3.png" alt="image"></p>
<p>可以清楚的看到执行顺序</p>
<p><img src="../images/nmapnse/4.png" alt="image"></p>
<p>我们再通过一个小例子看一看脚本的执行流程：</p>
<p><img src="../images/nmapnse/5.png" alt="image"></p>
<p>关于nmap各种库的引用可以查看（<a href="https://nmap.org/nsedoc/lib/）" target="_blank" rel="noopener">https://nmap.org/nsedoc/lib/）</a></p>
<p>比如再来编写一个demo，当80端口开放时，输出this is webserver</p>
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">local</span> shortport = <span class="built_in">require</span> <span class="string">"shortport"</span></span><br><span class="line"></span><br><span class="line">description = <span class="string">[[this is a test		]]</span></span><br><span class="line"></span><br><span class="line">author = <span class="string">"lengyi"</span></span><br><span class="line">license = <span class="string">"Same as Nmap--See http://nmap.org/book/man-legal.html"</span></span><br><span class="line">categories = &#123;<span class="string">"default"</span>&#125;</span><br><span class="line"></span><br><span class="line">portrule = <span class="function"><span class="keyword">function</span><span class="params">( host, port )</span></span></span><br><span class="line">    <span class="keyword">return</span> port.number == <span class="number">80</span>  <span class="keyword">and</span> port.state ==<span class="string">"open"</span></span><br><span class="line"><span class="keyword">end</span></span><br><span class="line"></span><br><span class="line">action = <span class="function"><span class="keyword">function</span><span class="params">(host, port)</span></span></span><br><span class="line">	<span class="keyword">return</span> <span class="string">"This is webserver"</span></span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
<p><img src="../images/nmapnse/6.png" alt="image"></p>
<p>记得每次执行使用ide更新脚本</p>
<p><img src="../images/nmapnse/7.png" alt="image"></p>
<h3 id="nse的api"><a href="#nse的api" class="headerlink" title="nse的api"></a>nse的api</h3><p>在刚才的demo中使用了nmap自带的api，也就是判断端口开放哪里，关于api，官网也给除了详细的文档(<a href="https://nmap.org/book/nse-api.html)常用的也就是host和port这两种。" target="_blank" rel="noopener">https://nmap.org/book/nse-api.html)常用的也就是host和port这两种。</a></p>
<p><strong>host：</strong></p>
<p><img src="../images/nmapnse/8.png" alt="image"></p>
<p><strong>port：</strong></p>
<p><img src="../images/nmapnse/9.png" alt="image"></p>
<h3 id="nse的库"><a href="#nse的库" class="headerlink" title="nse的库"></a>nse的库</h3><p>NSE中的库文件实现了代码的分离和重构，有助于脚本的开发，其存放在nselib文件夹中。</p>
<p><img src="../images/nmapnse/10.png" alt="image"></p>
<p>下面编写一个简单的库文件。</p>
<p><img src="../images/nmapnse/11.png" alt="image"></p>
<p>然后调用</p>
<p><img src="../images/nmapnse/12.png" alt="image"></p>
<p>常用的函数可以使用local关键字。</p>
<p>运行</p>
<p><img src="../images/nmapnse/13.png" alt="image"></p>
<h2 id="0x04-渗透脚本编写实战"><a href="#0x04-渗透脚本编写实战" class="headerlink" title="0x04 渗透脚本编写实战"></a>0x04 渗透脚本编写实战</h2><p>MacCMS V10后门为例编写一个nse脚本</p>
<p>关于漏洞的解释请戳：<a href="https://www.uedbox.com/post/59349/" target="_blank" rel="noopener">https://www.uedbox.com/post/59349/</a></p>
<p>编写的思想很简单，也就是确定开启了http服务，然后访问maccms10\extend\Qcloud\Sms\Sms.php文件存在即存在，虽然有点误报的感觉…</p>
<p>编写这个Poc需要使用http请求，也就是需要使用我们的http库，api地址：<a href="https://nmap.org/nsedoc/lib/http.html" target="_blank" rel="noopener">https://nmap.org/nsedoc/lib/http.html</a></p>
<p>常见的用法：</p>
<p>1、get请求</p>
<p>get (host, port, path, options)<br>主机、端口、路径、其他设置（socket超时时间，HTTP头以及其他参数）<br>返回一个标准响应表</p>
<p>2、post请求</p>
<p>post (host, port, path, options, ignored, postdata)<br>主机、端口、路径、其他设置、忽略向后兼容(一般设置nil)、post数据</p>
<p><img src="../images/nmapnse/14.png" alt="image"></p>
<p>最后的代码：</p>
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 引入相关库文件</span></span><br><span class="line"><span class="keyword">local</span> shortport = <span class="built_in">require</span> <span class="string">"shortport"</span></span><br><span class="line"><span class="comment">-- 对端口号以及服务进行匹配看是否满足要求</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">local</span> http = <span class="built_in">require</span> <span class="string">"http"</span> <span class="comment">-- 进行发包测试</span></span><br><span class="line"><span class="keyword">local</span> vulns = <span class="built_in">require</span> <span class="string">"vulns"</span> </span><br><span class="line"><span class="comment">-- 描述信息</span></span><br><span class="line">description = <span class="string">[[MacCMS V10 backdoor Webshell]]</span></span><br><span class="line"></span><br><span class="line">author = <span class="string">"lengyi"</span></span><br><span class="line"><span class="comment">-- 作者</span></span><br><span class="line">license = <span class="string">"Same as Nmap--See http://nmap.org/book/man-legal.html"</span></span><br><span class="line"><span class="comment">-- 遵循的开源协议</span></span><br><span class="line">categories = &#123;<span class="string">"vuln"</span>&#125;</span><br><span class="line"><span class="comment">-- 脚本分类</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">portrule = shortport.http</span><br><span class="line"><span class="comment">-- 指定为shortport.http，匹配所有类似http服务的端口</span></span><br><span class="line"></span><br><span class="line">action = <span class="function"><span class="keyword">function</span><span class="params">(host, port)</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">-- 制定漏洞报告和存储格式</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">local</span> vuln = &#123;</span><br><span class="line">    title = <span class="string">"MacCMS　backdoor Webshell"</span>,</span><br><span class="line">    <span class="comment">-- 这是强制的字段，状态有（NOT_VULN，LIKELY_VULN，VULN，Dos，和EXPLOIT）</span></span><br><span class="line">    state = vulns.STATE.NOT_VULN,   </span><br><span class="line">    description = <span class="string">[[</span></span><br><span class="line"><span class="string">		MacCMS backdoor Webshell.</span></span><br><span class="line"><span class="string">    ]]</span>,</span><br><span class="line">    IDS = &#123;</span><br><span class="line">        CVE = <span class="string">""</span></span><br><span class="line">    &#125;,</span><br><span class="line">    references = &#123;</span><br><span class="line">        <span class="string">'https://www.uedbox.com/post/59349/'</span></span><br><span class="line">    &#125;,</span><br><span class="line">    dates = &#123;</span><br><span class="line">        disclosure = &#123; year = <span class="string">'2019'</span>, month = <span class="string">'10'</span>, day = <span class="string">'14'</span> &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">-- 创建一个新的报告对象，所需参数为（self，script_name，host，port），返回的值为报告对象</span></span><br><span class="line"><span class="keyword">local</span> vuln_report = vulns.Report:new(SCRIPT_NAME, host, port)</span><br><span class="line"></span><br><span class="line">  <span class="comment">-- 编写头部信息</span></span><br><span class="line"><span class="keyword">local</span> options = &#123; header = &#123;</span><br><span class="line">      [<span class="string">"Accept-Encoding"</span>] = <span class="string">"gzip, deflate"</span>,</span><br><span class="line">      [<span class="string">"Accept"</span>] = <span class="string">"*/*"</span>,</span><br><span class="line">      [<span class="string">"Accept-Language"</span>] = <span class="string">"en"</span>,</span><br><span class="line">      [<span class="string">"User-Agent"</span>] = <span class="string">"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)"</span>,</span><br><span class="line">      [<span class="string">"Connection"</span>] = <span class="string">"close"</span>,</span><br><span class="line">      [<span class="string">"Content-Type"</span>] = <span class="string">"text/xml"</span>,</span><br><span class="line">      [<span class="string">"Content-Length"</span>] = <span class="number">638</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">   <span class="keyword">local</span> testurl = <span class="string">"/extend/Qcloud/Sms/Sms.php"</span></span><br><span class="line">  <span class="comment">-- 进行发包请求，传入主机名端口，方法，路径以及头部信息</span></span><br><span class="line">  <span class="keyword">local</span> response = http.get(host, port, testurl,&#123; options = options &#125;)</span><br><span class="line">   <span class="comment">-- 查看返回包，如果返回包里有东西，状态码为200,设定漏洞模版信息中的状态字段为存在漏洞。</span></span><br><span class="line">  <span class="keyword">if</span> response <span class="keyword">and</span> response.<span class="built_in">status</span> == <span class="number">200</span> <span class="keyword">then</span></span><br><span class="line">    vuln.state = vulns.STATE.VULN</span><br><span class="line">  <span class="keyword">end</span></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">  <span class="comment">-- 报告漏洞信息。</span></span><br><span class="line">  <span class="keyword">return</span> vuln_report:make_output(vuln)</span><br><span class="line">  </span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
<p>最后的效果：</p>
<p><img src="../images/nmapnse/15.png" alt="image"></p>
<p>对上面漏洞信息的补充漏洞报告信息必须存放在一个表中，每个漏洞必须有其状态，state是在报告模版中必须要指定的一个字段，状态有（NOT_VULN，LIKELY_VULN，VULN，Dos，和EXPLOIT）<br>NOT_VULN：不存在漏洞。<br>LIKELY_VULN：应该存在漏洞，只是做了一个简单的对比，存在一定的误报。<br>VULN：被证实存在漏洞。<br>EXPLOIT：存在漏洞并且已经测试成功。这条状态会自动设置。<br>DoS：存在拒绝服务攻击，状态会被自动设置。</p>
<p>上方NSE脚本中，先将state字段预设置为不存在漏洞。如果存在漏洞再将字段进行修改并将其漏洞信息进行输出</p>

      
    </div>

    

    
    
    

    <div>
      
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/nmapnse/">nmap插件编写</a></p>
  <p><span>文章作者:</span><a href="/" title="访问 冷逸 的个人博客">冷逸</a></p>
  <p><span>发布时间:</span>2020年02月09日 - 09:02</p>
  <p><span>最后更新:</span>2020年02月27日 - 15:02</p>
  <p><span>原始链接:</span><a href="/nmapnse/" title="nmap插件编写">https://lengjibo.github.io/nmapnse/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://lengjibo.github.io/nmapnse/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
    $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
    });
    });  
</script>


      
    </div>
    <div>
      
        <div>
    
        <div style="text-align:center;color: #555;font-size:14px;">-------------The End-------------</div>
    
</div>

      
    </div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>Donate</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat.png" alt="冷逸 WeChat Pay"/>
        <p>WeChat Pay</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/zhifubao.jpg" alt="冷逸 Alipay"/>
        <p>Alipay</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/nmap/" rel="tag"><i class="fa fa-tag"></i> nmap</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div class="social_share">
            
               <div>
                 
  <div class="bdsharebuttonbox">
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
    <a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网"></a>
    <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
    <a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧"></a>
    <a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a>
    <a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
    <a href="#" class="bds_more" data-cmd="more"></a>
    <a class="bds_count" data-cmd="count"></a>
  </div>
  <script>
    window._bd_share_config = {
      "common": {
        "bdText": "",
        "bdMini": "2",
        "bdMiniList": false,
        "bdPic": ""
      },
      "share": {
        "bdSize": "16",
        "bdStyle": "0"
      },
      "image": {
        "viewList": ["tsina", "douban", "sqq", "qzone", "weixin", "twi", "fbook"],
        "viewText": "分享到：",
        "viewSize": "16"
      }
    }
  </script>

<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

               </div>
            
            
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/winlo/" rel="next" title="windows认证总结">
                <i class="fa fa-chevron-left"></i> windows认证总结
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/hero/" rel="prev" title="《悼李文亮先生》">
                《悼李文亮先生》 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Inhaltsverzeichnis
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Übersicht
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="http://ww1.sinaimg.cn/large/007F8GgBly1g7vony4ltaj308w08wq30.jpg"
                alt="冷逸" />
            
              <p class="site-author-name" itemprop="name">冷逸</p>
              <p class="site-description motion-element" itemprop="description">做一个温柔的人...</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">113</span>
                    <span class="site-state-item-name">Artikel</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">19</span>
                    <span class="site-state-item-name">Kategorien</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">120</span>
                    <span class="site-state-item-name">Tags</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/../../.deploy_git/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/lengjibo" target="_blank" title="GitHub"><i class="fa fa-fw fa-globe"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="qqlengyi@163.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-globe"></i>E-Mail</a>
                  
                </span>
              
            </div>
          
        <div id="music163player">
            <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=110 src="https://music.163.com/outchain/player?type=0&id=377079922&auto=1&height=90"></iframe>
          </div>
          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sqlmap.wiki/" title="青春's blog" target="_blank">青春's blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.addon.pub/" title="Yokeen's blog" target="_blank">Yokeen's blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://freeerror.org/" title="之乎者也's blog" target="_blank">之乎者也's blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.bugbank.cn/team/FrigidSword" title="漏洞银行" target="_blank">漏洞银行</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.vulbox.com/team/Frigid%20Sword%E5%AE%89%E5%85%A8%E5%9B%A2%E9%98%9F" title="漏洞盒子" target="_blank">漏洞盒子</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://godpang.github.io/" title="Mr.赵" target="_blank">Mr.赵</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://amliaw4.github.io/" title="amliaW4'S Blog" target="_blank">amliaW4'S Blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.se7ensec.cn/" title="se7en's Blog" target="_blank">se7en's Blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://ninjia.gitbook.io/secskill/" title="secskill" target="_blank">secskill</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.bug1024.cn/" title="ibug" target="_blank">ibug</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://wwcx.org/" title="Strjziny's Blog" target="_blank">Strjziny's Blog</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#0x01-nmap简介"><span class="nav-number">1.</span> <span class="nav-text">0x01 nmap简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#0x02-lua语言"><span class="nav-number">2.</span> <span class="nav-text">0x02 lua语言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#0x03-nse脚本编写"><span class="nav-number">3.</span> <span class="nav-text">0x03 nse脚本编写</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#nse基本格式"><span class="nav-number">3.1.</span> <span class="nav-text">nse基本格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#调用规则"><span class="nav-number">3.2.</span> <span class="nav-text">调用规则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nse的api"><span class="nav-number">3.3.</span> <span class="nav-text">nse的api</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nse的库"><span class="nav-number">3.4.</span> <span class="nav-text">nse的库</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#0x04-渗透脚本编写实战"><span class="nav-number">4.</span> <span class="nav-text">0x04 渗透脚本编写实战</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2014 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">冷逸</span>

  

  
</div>




  <div class="powered-by">Erstellt mit  <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> v3.7.1</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme – <a class="theme-link" target="_blank" href="https://theme-next.org">NexT.Muse</a> v6.4.0</div>






        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv" title="Total Visitors">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="site-pv" title="Total Views">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
	
    

    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>














  







  
  







  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.ui.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/canvas_sphere.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.4.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.4.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.4.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.4.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.4.0"></script>



  



  










  





  

  

  

  

  
  

  

  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?0c58a1486de42ac6cc1c59c7d98ae887"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
<script type="text/javascript" src="/js/src/love.js"></script>
